const Client = require('ssh2-sftp-client');

uploadDir('./build', '/root/xiaoqiang/wx/wx_doutu_server/client/')

function uploadDir(sourceDir, destDir) {
    const sftp = new Client();
    sftp.connect({
        host: '81.71.148.91',
        port: '22',
        username: 'root',
        password: 'zxc1230....'
    }).then(() => {
        return sftp.exists(destDir);
    }).then(isExist => {
        if (isExist !== 'd') {
            return sftp.mkdir(destDir, true)
        }
    }).then(() => {
        return sftp.uploadDir(sourceDir, destDir);
    }).then(() => {
        sftp.end()
    }).catch(e => {
        console.log('error', e.message)
    })

    sftp.on('upload', info => {
        console.log(`Listener: Uploaded ${info.source}`);
    });
}

